﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using shop.Model;

namespace shop.Web.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        [HttpGet]
        public async Task<JUser> GetUser(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return null;
            }

            return await DB.FSql.Select<JUser>()
                .Where(a => a.Isdel == false && a.Name == name)
                .ToOneAsync();
        }

        [HttpGet]
        public async Task DeleteUser(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }

            await DB.FSql.Update<JUser>()
                .Where(a => a.Isdel == false && a.Name == name)
                .Set(a => a.Isdel, true)
                .ExecuteAffrowsAsync();
        }


        [HttpGet]
        public async Task<IEnumerable<JUser>> GetAllUser()
        {
            return await DB.FSql.Select<JUser>()
                .Where(a => a.Isdel == false)
                .ToListAsync();
        }




    }
}
